import request from "@/utils/request";
import type {
  GetTrademarkListResponse,
  TrademarkItem,
  TrademarkList,
} from "./model/trademarkModel";
// 枚举类型
// 当前模块的所有请求地址定义在一起（统一定义接口地址）
const enum Api {
  getTrademarkList = "/admin/product/baseTrademark",
  getAllTrademarkList = "/admin/product/baseTrademark/getTrademarkList",
  addTrademark = "/admin/product/baseTrademark/save",
  updateTrademark = "/admin/product/baseTrademark/update",
  delTrademark = "/admin/product/baseTrademark/remove",
}

/**
 * 获取品牌分页列表
 * @param page 当前页码
 * @param limit 每页条数
 * @returns GetTrademarkListResponse
 */
export const getTrademarkListApi = (page: number, limit: number) => {
  // 第二个泛型参数就是请求数据类型
  return request.get<any, GetTrademarkListResponse>(
    Api.getTrademarkList + `/${page}/${limit}`
  );
};

/**
 * 获取所有品牌列表
 * @returns TrademarkList
 */
export const getAllTrademarkListApi = () => {
  return request.get<any, TrademarkList>(Api.getAllTrademarkList);
};

/**
 * 添加品牌
 * @param tmName 品牌名称
 * @param logoUrl 品牌LOGO
 * @returns null
 */
export const addTrademarkApi = (tmName: string, logoUrl: string) => {
  return request.post<any, null>(Api.addTrademark, {
    tmName,
    logoUrl,
  });
};

/**
 * 更新品牌
 * @param data TrademarkItem
 * @returns null
 */
export const updateTrademarkApi = (data: TrademarkItem) => {
  return request.put<any, null>(Api.updateTrademark, data);
};

/**
 * 删除品牌
 * @param id 品牌id
 * @returns null
 */
export const delTrademarkApi = (id: number) => {
  return request.delete<any, null>(Api.delTrademark + `/${id}`);
};
